var t = require;
var e = module;
var o = exports;
var Adv_skd=require("./Adv_skd");
var n =
        (this && this.__extends) ||
        (function () {
            var t = function (e, o) {
                return (t =
                    Object.setPrototypeOf ||
                    ({__proto__: []} instanceof Array &&
                        function (t, e) {
                            t.__proto__ = e;
                        }) ||
                    function (t, e) {
                        for (var o in e) e.hasOwnProperty(o) && (t[o] = e[o]);
                    })(e, o);
            };
            return function (e, o) {
                function n() {
                    this.constructor = e;
                }
                t(e, o), (e.prototype = null === o ? Object.create(o) : ((n.prototype = o.prototype), new n()));
            };
        })(),
    r =
        (this && this.__decorate) ||
        function (t, e, o, n) {
            var r,
                a = arguments.length,
                i = a < 3 ? e : null === n ? (n = Object.getOwnPropertyDescriptor(e, o)) : n;
            if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) i = Reflect.decorate(t, e, o, n);
            else
                for (var s = t.length - 1; s >= 0; s--)
                    (r = t[s]) && (i = (a < 3 ? r(i) : a > 3 ? r(e, o, i) : r(e, o)) || i);
            return a > 3 && i && Object.defineProperty(e, o, i), i;
        };
Object.defineProperty(o, "__esModule", {value: !0});
var a = t("BootConst"),
    i = t("EventData"),
    s = t("GameData"),
    c = t("Util"),
    l = t("View"),
    u = t("Platforms"),
    p = t("WatchVideo"),
    f = t("ConfS"),
    d = t("mainView"),
    h = t("rewards"),
    y = t("topBar"),
    g = t("luckdrawBoxPreview"),
    v = cc._decorator,
    m = v.ccclass,
    _ =
        (v.property,
        (function (t) {
            function e() {
                var e = (null !== t && t.apply(this, arguments)) || this;
                return (e.res = "luckdraw"), (e.isMask = !0), (e.isturntable = !1), (e.index = new i.default(0)), e;
            }
            return (
                n(e, t),
                (e.prototype.view_累计次数 = function (t, e) {
                    t.string = "" + c.isdaycount(e);
                }),
                (e.prototype.onEnable = function () {
                    Adv_skd.default.instance.showInterstitialAd();
                    if ((this.showView(y.default).buttonActive(!1), this.isturntable)) {
                        (this.turntable = this.find("turntable")), (this.turntable.angle = 0);
                        for (var t = f.DatasManager.ZhuanpanDatas, e = 0; e < t.length; e++) {
                            var o = t[e];
                            c.showLable("06/" + e + "/L", this.view, "x" + o.Need);
                        }
                    } else
                        for (var n = this.find("items"), r = f.DatasManager.ZhuanpanDatas, a = 0; a < r.length; a++) {
                            o = r[a];
                            var i = cc.find("" + a, n);
                            c.setSpriteUrl("icon", i, o.icon), c.showLable("text", i, "x" + o.Need);
                        }
                }),
                (e.prototype.onDisable = function () {
                    this.showView(y.default).buttonActive(!0), this.showView(d.default);
                }),
                (e.prototype.one_at_random = function () {
                    for (var t = f.DatasManager.ZhuanpanDatas, e = 0, o = 0; o < t.length; o++) e += t[o].Rate;
                    var n = c.RandomInt(1, e),
                        r = 0,
                        a = -17.5;
                    for (o = 0; o < t.length; o++) {
                        var i = t[o];
                        if (n <= (r += i.Rate)) return {data: i, 随机角度: c.RandomInt(a, a + 45 - 5)};
                        a += 45;
                    }
                }),
                (e.prototype._旋转 = function (t, e) {
                    var o = this,
                        n = 360 - (this.turntable.angle % 360),
                        r = this.turntable.angle + n + 2160 + e;
                    c.stopInput(),
                        cc
                            .tween(this.turntable)
                            .to(4, {angle: r}, {easing: "circInOut"})
                            .call(function () {
                                c.stopInput(!1);
                                var e = o.showView(h.default);
                                (e.titleText = "恭喜"),
                                    (e.icon = t.icon),
                                    (e.count = t.Need),
                                    e.callback(o, function (e) {
                                        c.reward(t.Type, t.Need * e, "转盘" + e + "倍领取");
                                    }),
                                    o.is免费抽奖() &&
                                        ((s.default.上一次免费抽奖的时间戳 = Date.now()),
                                        console.log("记录免费抽奖时间", s.default.上一次免费抽奖的时间戳)),
                                    s.default.旋转转盘时间记录.push(Date.now()),
                                    (s.default.旋转转盘时间记录 = s.default.旋转转盘时间记录);
                            })
                            .start();
                }),
                (e.prototype._轮盘 = function (t) {
                    for (
                        var e = this,
                            o = f.DatasManager.ZhuanpanDatas,
                            n = this.index.value,
                            r = o.indexOf(t),
                            a = n + 6 * o.length;
                        a % o.length != r;

                    )
                        a++;
                    (this.obj = {v: n}),
                        c.stopInput(),
                        cc
                            .tween(this.obj)
                            .to(3, {v: a}, {easing: "circInOut"})
                            .call(function () {
                                (e.obj = null), c.stopInput(!1);
                                var o = e.showView(h.default);
                                (o.titleText = "恭喜"),
                                    (o.icon = t.icon),
                                    (o.count = t.Need),
                                    o.callback(e, function (e) {
                                        c.reward(t.Type, t.Need * e, "转盘" + e + "倍领取");
                                    }),
                                    e.is免费抽奖() &&
                                        ((s.default.上一次免费抽奖的时间戳 = Date.now()),
                                        console.log("记录免费抽奖时间", s.default.上一次免费抽奖的时间戳)),
                                    s.default.旋转转盘时间记录.push(Date.now()),
                                    (s.default.旋转转盘时间记录 = s.default.旋转转盘时间记录);
                            })
                            .start();
                }),
                (e.prototype.update = function (t) {
                    if (this.obj) {
                        var e = f.DatasManager.ZhuanpanDatas,
                            o = Math.round(this.obj.v);
                        this.index.value = o % e.length;
                    }
                }),
                (e.prototype.is免费抽奖 = function () {
                    return !c.is今天(s.default.上一次免费抽奖的时间戳);
                }),
                (e.prototype.clickBtn = function () {
                    var t = this.one_at_random();
                    this.isturntable ? this._旋转(t.data, t.随机角度) : this._轮盘(t.data),
                        u.default.platformCtrl.dd(a.dd.LuckDraw, {
                            LuckDrawCount: s.default.旋转转盘时间记录.length,
                            LuckDrawCountToday: c.isdaycount(s.default.旋转转盘时间记录),
                            EventDate: Date.now(),
                            GiftType: t.data.Type,
                            GiftCount: t.data.Need
                        });
                }),
                (e.prototype.clickBox = function (t) {
                    var e = f.DatasManager.ZhuanpanChestDatas[t],
                        o = s.default.所有抽奖宝箱的领取时间[e.ID];
                    if (c.is今天(o)) c.toast("这个宝箱你今天已经领取了,明天再来吧!");
                    else {
                        var n,
                            r = c.isdaycount(s.default.旋转转盘时间记录);
                        if (e.Times > r) ((n = this.showView(g.default)).icon = e.Icon), (n.count = e.Need);
                        else
                            ((n = this.showView(h.default)).titleText = "恭喜"),
                                (n.icon = e.Icon),
                                (n.count = e.Need),
                                n.callback(this, function (t) {
                                    c.reward(e.Type, e.Need * t, "转盘宝箱" + t + "倍领取"),
                                        (s.default.所有抽奖宝箱的领取时间[e.ID] = Date.now()),
                                        (s.default.所有抽奖宝箱的领取时间 = s.default.所有抽奖宝箱的领取时间);
                                });
                    }
                }),
                (e.prototype.onClick = function (t) {
                    var e = this;
                    switch (t) {
                        case "close":
                            this.hideView();
                            break;
                        case "btn":
                            this.is免费抽奖()
                                ? this.clickBtn()
                                : p.default.show(a.dd.luckdraw, function () {
                                      e.clickBtn();
                                  });
                            break;
                        case "0":
                            this.clickBox(0);
                            break;
                        case "1":
                            this.clickBox(1);
                            break;
                        case "2":
                            this.clickBox(2);
                    }
                }),
                (e = r([m], e))
            );
        })(l.default));
o.default = _;
